import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), vueJsx(), vueDevTools()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  build: {
    outDir: 'dist/meetadmin',
  },
  base: '/meetadmin/',
  server: {
    host: '0.0.0.0',
    port: 8171,
    proxy: {
      '^/api': {
        target: 'https://meet.yeebok.com', // 测试环境
        // target: 'https://meet.apt11.net',
        changeOrigin: true,
        // configure: (proxy) => {
        //   proxy.on('proxyReq', (proxyReq, req, res) => {
        //     const pathSegments = req
        //       .url!.split('/')
        //       .filter((s) => s != '')
        //       .map((s) => s.split('?')[0])

        //     const fileName = pathSegments[pathSegments.length - 1]
        //     // eslint-disable-next-line @typescript-eslint/no-require-imports
        //     const jsonData = require(`./mock/${fileName}.json`)
        //     res.end(JSON.stringify(jsonData))
        //   })
        // },
      },
    },
  },
})
